package com.menu.web.controller.attributePublic;

import com.menu.common.annotation.Log;
import com.menu.common.core.controller.BaseController;
import com.menu.common.core.domain.AjaxResult;
import com.menu.common.enums.BusinessType;
import com.menu.common.utils.poi.ExcelUtil;
import com.menu.system.domain.MenuProductsAttribute;
import com.menu.system.service.IMenuProductsAttributeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品公有属性Controller
 *
 * @author ruoyi
 * @date 2024-06-28
 */
@RestController
@RequestMapping("/system/attribute")
public class MenuProductsAttributeController extends BaseController {
    @Autowired
    private IMenuProductsAttributeService menuProductsAttributeService;
    /*测试svn*/

    /**
     * 查询产品公有属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attributePublic:list')")
    @GetMapping("/list")
    public AjaxResult list(MenuProductsAttribute menuProductsAttribute) {
        List<MenuProductsAttribute> list = menuProductsAttributeService.selectMenuProductsAttributeList(menuProductsAttribute);
        return success(list);
    }
    /*查询类别下的模板信息*/

    /**
     * 导出产品公有属性列表
     */
    @PreAuthorize("@ss.hasPermi('system:attributePublic:export')")
    @Log(title = "产品公有属性", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MenuProductsAttribute menuProductsAttribute) {
        List<MenuProductsAttribute> list = menuProductsAttributeService.selectMenuProductsAttributeList(menuProductsAttribute);
        ExcelUtil<MenuProductsAttribute> util = new ExcelUtil<MenuProductsAttribute>(MenuProductsAttribute.class);
        util.exportExcel(response, list, "产品公有属性数据");
    }

    /**
     * 获取产品公有属性详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attributePublic:query')")
    @GetMapping(value = "/{attributeId}")
    public AjaxResult getInfo(@PathVariable("attributeId") Long attributeId) {
        return success(menuProductsAttributeService.selectMenuProductsAttributeByAttributeId(attributeId));
    }

    /**
     * 新增产品公有属性
     */
    @PreAuthorize("@ss.hasPermi('system:attributePublic:add')")
    @Log(title = "产品公有属性", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MenuProductsAttribute menuProductsAttribute) {
        return toAjax(menuProductsAttributeService.insertMenuProductsAttribute(menuProductsAttribute));
    }

    /**
     * 修改产品公有属性
     */
    @PreAuthorize("@ss.hasPermi('system:attributePublic:edit')")
    @Log(title = "产品公有属性", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MenuProductsAttribute menuProductsAttribute) {
        return toAjax(menuProductsAttributeService.updateMenuProductsAttribute(menuProductsAttribute));
    }

    /**
     * 删除产品公有属性
     */
    @PreAuthorize("@ss.hasPermi('system:attributePublic:remove')")
    @Log(title = "产品公有属性", businessType = BusinessType.DELETE)
    @DeleteMapping("/{attributeIds}")
    public AjaxResult remove(@PathVariable Long[] attributeIds) {
        return toAjax(menuProductsAttributeService.deleteMenuProductsAttributeByAttributeIds(attributeIds));
    }
}
